<?php 
$user_id=$_REQUEST['user_id'];
$date=$_REQUEST['date'];
$sql="SELECT SUM(package_price),user_id,DATE_FORMAT(sale_time,'%Y-%m'),COUNT(*),SUM(bonus) FROM zy_bonus where user_id=".$user_id." AND DATE_FORMAT(sale_time,'%Y-%m')= '".$date."' GROUP BY user_id";
$connection = Yii::app()->db;
$command = $connection->createCommand($sql);
$result = $command->queryAll();
$user=User::model()->find('user_id='.$user_id);
if(isset($_POST['submit'])){
	Rebatecommission::model()->createsaleRebatecommission();
	header('Location: admin');
}
?>
<form name="myform" method="post" action="">
<input name="user_id" id="user_id" value="<?php echo $user_id;?>" type="hidden" />
<input name="date" id="date" value="<?php echo $_REQUEST['date']?>" type="hidden"/>
  <div>
  代理人:<?php  echo $user->user_name;?><br/>
 返点金额:<?php 
 for ($i=0;$i<count($result);$i++){
$number =$result[$i]['COUNT(*)'];
if($number>0 && $number<=100){
	$fandian_rate=1;
}elseif($number>=101 && $number<=200){
	$fandian_rate=3;
}elseif($number>=201 && $number<=300){
	$fandian_rate=5;
}
echo $result[$i]['SUM(package_price)']*$fandian_rate/100; }?>
 <table class="responsive table table-striped table-bordered">
 	<thead>
 	<tr>
 	<th>返点比例</th><th>金额</th><th>返点金额</th>
 	</tr>
 	</thead>
 	<tbody>
 	<tr>
 	<?php 
 	for ($i=0;$i<count($result);$i++){
	?>
	<input type="hidden" name="number" id="number" value="<?php echo $number;?>"/>
 	<td><?php echo $fandian_rate;?><input type="hidden" name="rate" id="rate" value="<?php echo $fandian_rate;?>"/></td>
 	<td><?php echo $result[$i]['SUM(package_price)'];?><input type="hidden" name="sum_package_price" id="sum_package_price" value="<?php echo $result[$i]['SUM(package_price)'];?>"/></td>
 	<td><?php echo $result[$i]['SUM(package_price)']*$fandian_rate/100;?><input type="hidden" name="fandian_money" id="fandian_money" value="<?php echo $result[$i]['SUM(package_price)']*$fandian_rate/100;?>"/></td>
 	<?php } ?>
 	</tr>
 	</tbody>
  </table>
  <?php if(yii::app()->user->level==1){?>
          <input type="submit" name="submit" value="<?php echo Yii::t('base','send');?>" id="send"/>
       <?php } ?>
</form>
